/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package pku.lbs.web.utils;

import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.apache.commons.codec.binary.Base64;
/**
 *
 * @author yongchao
 */
public class Tools {

    static public String md5(String s) {
        try {
            MessageDigest m = MessageDigest.getInstance("MD5");
            m.update(s.getBytes(), 0, s.length());
            s = new BigInteger(1, m.digest()).toString(16);
        } catch (NoSuchAlgorithmException ex) {
            Logger.getLogger(Tools.class.getName()).log(Level.SEVERE, null, ex);
        }
        return s;
    }
    static public String encodeBase64(String s){
        return new String(Base64.encodeBase64(s.getBytes()));
    }

    static public String decodeBase64(String s){
        return new String(Base64.decodeBase64(s.getBytes()));
    }
}
